home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 1
/
Cream of the Crop 1.iso
/
UTILITY
/
5MIN_DOS.ARJ
/
16.DOC
< prev
next >
Wrap
Text File
|
1992-04-02
|
6KB
|
177 lines
.BAT (Batch Files)
PURPOSE:
Batch files combine a certain sequence of commands
and the entire sequence of commands is run simply
by typing the name of the batch file.
NOTE:
Batch files are very useful if you find that you are
repeatedly typing the same sequence of commands in
hopes of performing a common task. Also note that
all batch files must include the ".bat" extension in
their filenames (example: message.bat). By using
batch files you only have to remember to type one
command, the name of the specific batch file, instead
of several.
CREATING BATCH FILES:
You can create a batch file using
Edlin (the MS-DOS line editor) or
any other line editor (such as Q),
by using the "copy" command, or by
using a word processor that saves
files as ASCII text.
IMPORTANT:
1) You must name each batch file with an extension
of .bat
2) When you want to execute a batch file, you type
only its filename and not the extension.
3) You can specify the name of another batch file
as the last command in a batch file. When you
do this, you are able to call one batch file
from another when the first has finished.
4) Setting the directory or drive affects every
subsequent command in the batch file.
5) If you remove the disk that contains a batch
file being run, DOS prompts you to reinsert
the disk in order to continue following the
commands in the file.
COMMANDS USED IN BATCH FILES:
COMMAND: USAGE:
cls Clears the screen
echo off Used so commands in batch file are not
echoed to the screen and cluttering up
what you really want to say.
echo Everything typed after the word "echo"
appears on the screen excluding the
word "echo" when the batchfile is run.
pause Pauses during the process of a batch file
rem Displays a comment or remark in the batch
file, but doesn't show up on the screen
when the batch file is executed
dir Displays the default directory of the disk
in the default drive
date Asks you to set the date (used mainly in
autoexec.bat)
time Asks you to set the current time (used mainly
in autoexec.bat)
call Calls one batch file from another without
ending itself
MORE SOPHISTICATED COMMANDS
COMMAND USAGE
for Performs a command for a set of files
goto Processes commands starting with the line
after the specified label
if Performs a command if a condition is met
EXAMPLE:
The following is a sample batch file created through
the use of the "copy" command. Through this batch
file you want to format and check new disks. To do
this, follow these easy steps:
1) First type the following command:
copy con mydir.bat
Then hit the ENTER key. This command tells DOS to
copy the information from the keyboard (console)
to the file mydir.bat
2) Next, type the following lines, hitting the ENTER
key after each one:
rem This is a file to display
rem my directory and pause it.
pause HIT THE ENTER Key When Ready
dir *.*/W/P
3) Then, after the last line, press the CONTROL key
and Z at the same time to save the batch file.
The message "1 file(s) copied to show that the
file has been created.
4) To execute or run the file, simply type:
mydir
CREATING BATCH FILES WITH REPLACEABLE PARAMETERS
PURPOSE:
You may want to create a program and run it with
different sets of data. These different sets of
data may be stored in various DOS files. Through
DOS, you are able to create a batch file with
replaceable parameters where a parameter is a
common option that you define. Named %0 through %9,
these parameters hold the places for the values
that you supply when you give the batch command.
These replaceable parameters are useful because
they make certain batch files easier to use and
more flexible.
EXAMPLE:
You could create a file that says Good morning
and issues instructions.
1) First type the following and then hit the
ENTER key:
copy con Myfile.bat
2) Then type the following lines:
echo off
cls
echo Good Morning %1
echo Hope all is well today.
echo/
echo Please don't forget to
echo pick up the laundry %1
echo/
echo Thanks %1
pause
3) Next, hit the CONTROL key and Z at the same
time to save the batch file, and then hit
ENTER.
TO RUN THE BAT FILE type:
myfile Doris